
print inside test phone api script.

set daysAhead = 4

# Note: this represents the final result of the script returned to the fluentscript app
# Note: this fluentscript app will check if the success is true and message if any error
set result = { success: no , data: nothing , format: 'tableview', message: nothing }


# @summary: Checks the contacts to see if there are any upcoming birthdays
# @arg: name: contacts,   type: list(contacts),  required: yes
step check_contacts ( contacts )
{
	# Note: listof( name, birthday, message ) creates a table structure with 3 columns ( name, birthday, message )
	# Note: you can then do table.add column1Value, column2Value, column3Value  
	# Note: for the time being, you can only create tables with 4 columns ( restriction to be removed later )
	set birthdays = listof( name , birthday , message )
	
	println contacts are:
	printtable( contacts )
	
	# Note: with each plugin makes looping and data access easier:
	# Note: 1. you don't have to write the collection name 'contacts' as in 'for( contact in contacts )
	# Note: 2. inside the with each block, you don't have to prefix 'contact.' as in 'contact.name' you can write 'name'
	with each contact
	{
		if contact.birthday is today then
			birthdays.add ( contact.first, contact.birthday, contact.name + ' birthday today !' )
        
		else if contact.birthday < 2 days away then 
			birthdays.add ( contact.first, contact.birthday, ' 2 days away' )
		
		else if contact.birthday < daysAhead days away then
			birthdays.add ( contact.first, contact.birthday, ' coming up in ' + daysAhead )
		
	}
	result.data = birthdays
	result.success = any birthdays ?
}


# Note: This setups the asynchronous calls for windows phone but is also compatible for
#       if we ever move to android.
run step check_contacts on get_all_contacts_in_group 'close friends'


printresults()
